home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-01 | 5.0 KB | 164 lines | [TEXT/MPS ] |
- //
- // atom0.c
- //
- // Demonstration of a format0 action atom and compatibility with
- // Installer Engine 4.1.
- //
- // Under Installer 4.0.3, a dialog is provided that allows the
- // user to select the return value for the action atom.
- //
- // Scriptwriters should be aware that the return values
- // and the actions that they invoke from the installer
- // are different depending on which format of action atom
- // is being used.
- //
- // NOTE: Displaying dialogs from within action atoms and other
- // code resources is discouraged. Installer scripts that
- // display dialogs from within code resources will not work
- // when running under Installer Engine 4.1. This example shows
- // you how you can write action atom code that will display a
- // dialog under Installer 4.0.3 and still be compatible with
- // Installer Engine 4.1. For more information on script
- // compatibility with Installer Engine 4.1 see the "Engine 4.1
- // Compatiblity Issues" document in the Installer 4.1 folder of
- // the Installer SDK.
- //
- // Additionally, this example completely ignores good user
- // interface design practices for the purpose of demonstrating the
- // installer in regards to return values from an action atom.
- //
- // Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
- //
-
- #include <Traps.h>
- #include <Types.h>
- #include <dialogs.h>
-
- // this line replaces #include "ActionAtomHeader.h" used in previous 4.0.3 action atoms
- #include "InstallerScript.h"
-
- // this is needed for highlighting the default button in dialog
- pascal OSErr SetDialogDefaultItem ( DialogPtr theDialog,
- short newItem ) = {0x303C,0x0304,0xAA68};
-
- // NOTE: The name of this function 'ActionAtomFormat0' should
- // match that specified in the -m option for the line in the
- // makefile that compiles this action atom.
-
- pascal Boolean ActionAtomFormat0( AAPBRecPtr atomRecPtr )
- {
-
- DialogPtr theDialog; // for dialog
- OSErr theOSError = 0; // for errors
-
- short theItemHit; // gets user response from ModalDialog()
- short iType; // gets control type from GetDItem()
- Handle iHandle; // gets control handle from GetDItem()
- Rect iRect; // gets control rect from GetDItem()
-
- short currRadioButton = 2; // current selected radio button
- short gettingUserResponse = true; // flag for while loop
-
- short theStatus = 0; // value to return from function
-
- // retrieve DLOG/DITL 128 from compiled resource script
- theDialog = GetNewDialog( 128, nil, (WindowPtr) -1 );
-
- // Installer Engine 4.1 will indicate that a window cannot be displayed by
- // patching GetNewDialog and returning NULL.
- if( theDialog != NULL )
- {
- // We are running with Installer 4.0.3
- // Display the dialog.
-
- // activate OK button when enter or return key is pressed
- theOSError = SetDialogDefaultItem( theDialog, 1 );
-
- // set up the radio button group ( controls 2 - 3 )
- GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // select the new dialog
- SelectWindow( (WindowPtr) theDialog );
-
- // show the new dialog
- ShowWindow( (WindowPtr) theDialog );
-
- // keep getting response from user until
- // the OK is activated in the new dialog
- gettingUserResponse = true;
- while ( gettingUserResponse )
- {
- // get user selection from the new dialog
- ModalDialog( nil, &theItemHit );
- switch ( theItemHit )
- {
- // first control is the OK key
- case( 1 ) :
- // exit loop
- gettingUserResponse = false;
- break;
-
- // all other controls in dialog are radio buttons
- default :
- // continue with loop
- gettingUserResponse = true;
-
- // if the radio button selection changed
- if ( currRadioButton != theItemHit )
- {
- // turn previous radio button off
- GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // turn current radio button on
- GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- // save current radio button choice
- currRadioButton = theItemHit;
- }
- break;
- }// switch
-
- }// while
-
- // get rid of the new dialog
- DisposDialog( theDialog );
-
- // select a value to return from this function according to
- // which radio button was selected in the dialog
- switch ( currRadioButton )
- {
- // return false
- case( 2 ) : theStatus = false; // user selected to return 0
- break;
-
- // return true
- case( 3 ) : theStatus = true; // user selected to return 1
- break;
-
- }
-
- // return value selected by user in dialog
- return( theStatus );
-
- }// if theDialog != NULL
- else
- {
- // We are running under Installer Engine 4.1, which doesn't interact with user.
- // Do default action here rather than trying to display a dialog.
- // Let's say the default action for this example is to return true.
-
- return (true);
- }
- }
-
-
-
-
-
-